<template>
  <div class="navbar">
    <!-- 开启路由模式  启用该模式会在激活导航时以 index 作为 path 进行路由跳转 -->
    <el-menu
      :router="true"
      :default-active="defaultUrl"
      class="el-menu-vertical-demo"
      background-color="#263859"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <el-menu-item index="/home">
        <i class="el-icon-s-home"></i>
        <span slot="title">首页</span>
      </el-menu-item>
      <el-menu-item index="/member">
        <i class="el-icon-user-solid"></i>
        <span slot="title">会员管理</span>
      </el-menu-item>
      <el-menu-item index="/supplier">
        <i class="el-icon-s-shop"></i>
        <span slot="title">供应商管理</span>
      </el-menu-item>
      <el-menu-item index="/goods">
        <i class="el-icon-s-goods"></i>
        <span slot="title">商品管理</span>
      </el-menu-item>
      <el-menu-item index="/staff">
        <i class="el-icon-s-custom"></i>
        <span slot="title">员工管理</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      defaultUrl: "/home"
    };
  },

  components: {},
  mounted() {
    // 实现导航栏动态高亮
    let href = window.location.href;
    this.defaultUrl = href.split("/#")[1];
  },
  //监听路由变化
  watch: {
    $route: "getPath"
  },
  methods: {
    getPath() {
      this.defaultUrl = this.$route.path;
    }
  }
};
</script>

<style scoped>
</style>